package cn.mazexal.exambg.common.models;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author: Mazexal
 * Date: 2021/10/7
 */
public class PageList<T> implements Serializable {
    private int total;
    private int pageIndex;
    private int pageSize;
    private List<T> list;

    public PageList() {
        this.pageIndex = 1;
        this.pageSize = 15;
        this.total = 0;
        this.list = Collections.emptyList();
    }

    public PageList(Integer pageIndex, Integer pageSize) {
        if (pageIndex == null) {
            pageIndex = 1;
        }
        if (pageSize == null) {
            pageSize = 15;
        }
        this.pageIndex = pageIndex;
        if (pageSize > 50) {
            pageSize = 50;
        }
        this.pageSize = pageSize;
    }

    public PageList(List<T> list, Integer pageIndex, Integer pageSize, int total) {
        if (pageIndex == null) {
            pageIndex = 1;
        }
        if (pageSize == null) {
            pageSize = 15;
        }
        this.list = list;
        this.pageIndex = pageIndex;
        if (pageSize > 50) {
            pageSize = 50;
        }
        this.pageSize = pageSize;
        this.total = total;
    }

    /**
     * 大页码分页对象
     *
     * @param pageIndex
     * @param pageSize  任意值的每页数量
     * @return
     */
    public static PageList ofBigPageSize(int pageIndex, int pageSize) {
        PageList pageList = new PageList();
        pageList.setPageIndex(pageIndex);
        pageList.setPageSize(pageSize);
        return pageList;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPageCursor() {
        return (this.pageIndex - 1) * this.pageSize;
    }
}
